/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package amd.core;

import java.io.File;
import org.pdfbox.pdmodel.PDDocument;

/**
 *
 * @author Latifah Dwi Nurachma
 */
public class FileOperations {

    public static void copyFilePdf(String srcFile, String destFile) throws Exception{
        File f1 = new File(srcFile);
        File f2 = new File(destFile);
        if (!f2.isDirectory()){
            f2= f2.getParentFile();
        }
        String destName = f2.getPath()+"/"+f1.getName();
        int nameLength = destName.length()-4;
        PDDocument doc = PDDocument.load(f1);
        int i=1;
        while(new File(destName).exists()){
            String nameExtension = "(" + i +")";
            destName = destName.substring(0, nameLength) + nameExtension + ".pdf";
            i++;
        }
        doc.save(destName);
        doc.close();
    }

    public static void moveFilePdf(String srcFile, String destFile) throws Exception{
        copyFilePdf(srcFile, destFile);
        File f1 = new File(srcFile);
        f1.delete();
    }
}
